package components.game
{
	import SEApp.se_util;
	
	import UIFree.ObjectEvent;
	import UIFree.uif_component;
	
	import classes.clt_events;
	import data.clt_data;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;

	public class clt_gameItem extends clt_collageItem {
		public function clt_gameItem(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, gameData:Object=null, styleClass:String='') {
			super(parent, ax, ay, awidth, aheight, gameData, styleClass);
		}

		override protected function getMenuList():Array {
			var menuList: Array = [
				{caption: clt.classes.locale.VIEWCOLLAGE, method: 'doView'},
				{caption: clt.classes.locale.USERCOLLAGES, method: 'doCollageView'}
			];
			
			if (_dataItem.uid == clt.externalServer.viewer_id)
			 	menuList.push({caption: clt.classes.locale.DELETECOLLAGE, method: 'doRemoveCollage'});
			else menuList.push({caption: clt.classes.locale.GOTOAUTOR, method: 'doBlog'});
			
			if (clt.externalServer.isAdmin())
				menuList.push({caption: clt.classes.locale.IMAGELINK, method: 'doImageLink'});
			
			if (!clt.isBanUser) menuList.push({caption: clt.classes.locale.COMPLAINTOCOLLAGE, method: 'doBanRequest'});
			
			return menuList;
		}
		
		public function doBanRequest(): void {
			clt.workspace.dispatchEvent(new ObjectEvent(clt_events.BANREQUEST, _dataItem));
		}
		
		override protected function updateBounds():uif_component {
			super.updateBounds();
			if (_prevImage) _prevImage.x = (width - _prevImage.width) / 2;
			if (_label) _label.x = (width - _label.width) / 2;
			return this;
		}
		
		public function doCollageView(): void {
			clt.workspace.dispatchEvent(new ObjectEvent(clt_events.USERCOLLAGES, data));
		}
		
		public function doBlog(): void {
			navigateToURL(new URLRequest(_dataItem.link));
		}
		
		public function doImageLink(): void {
			navigateToURL(new URLRequest(clt_servers.GAME_URL + _dataItem.id + clt_data.JPGEXT));
		}
		
		public function doRemoveCollage(): void {
			clt.internalServer.removeGame(clt.externalServer.viewer_id, _dataItem.id, function(data: Object): void {
				clt.workspace.dispatchEvent(new Event(clt_events.UPDATEGAME));
			})
		}
		
		override protected function buttonRelease(e:MouseEvent):void {
			menu.showMenu();
		} 
	}
}